home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / count.bit < prev    next >
Text File  |  1995-03-23  |  1KB  |  32 lines

  1. Article 4686 of comp.sys.handhelds:
  2. Path: en.ecn.purdue.edu!noose.ecn.purdue.edu!news.cs.indiana.edu!samsung!uakari.primate.wisc.edu!sdd.hp.com!wuarchive!uunet!mcsun!hp4nl!charon!jurjen
  3. From: jurjen@cwi.nl (Jurjen NE Bos)
  4. Newsgroups: comp.sys.handhelds
  5. Subject: HP28/48: Hamming weight of binary number (BITS)
  6. Message-ID: <3053@charon.cwi.nl>
  7. Date: 1 Mar 91 13:28:04 GMT
  8. Sender: news@cwi.nl
  9. Organization: STORC, Veldhoven
  10. Lines: 17
  11. Originator: jurjen@lijster.cwi.nl
  12.  
  13.  
  14. Everybody who has had a HP16 knows that it sometimes is very convenient to
  15. compute the number of 1 bits in a number.
  16. Computing this on a HP28 or HP48 seems to take some time.  A recent discussion
  17. in comp.arch yielded a much more efficient solution.  I changed it a little
  18. bit to make it work for 64 bits, and translated it into RPL.  The program is
  19. shown below.
  20. Happy Hacking!
  21.  
  22. BITS:
  23. \<< # 7777777777777777h OVER SR OVER AND
  24.   DUP2 SR AND ROT OVER SR AND + + -
  25.   DUP SR SR SR SR + #F0F0F0F0F0F0F0Fh AND
  26.   #FF DUP2 / * -
  27. \>>
  28.  
  29. I leave proving that this works as an exercise to the reader :-)
  30.  
  31.  
  32.